<template>
  <el-dialog class="off_dialog" width="500px" title="下架" :visible.sync="dialogVisible" :close-on-click-modal="false">
    <p class="text-center tip">您确定要下架处理该商品吗？</p>
    <el-form ref="ruleForm" class="ruleForm" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="原因" prop="reason">
        <el-select v-model="form.reason" placeholder="请选择">
          <el-option label="图片不符合规范" value="图片不符合规范" />
          <el-option label="商品内容有敏感字符" value="商品内容有敏感字符" />
          <el-option label="其他原因" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item v-show="form.reason == 3" label="其他原因">
        <el-input v-model="form.other" type="textarea" :rows="4" placeholder="请输入备注原因信息！例如：图片不符合规范" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogVisible = false">取 消</el-button>
      <el-button size="small" type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { itemDownShelf } from '@/api/audit'
export default {
  data() {
    return {
      form: {
        reason: '',
        other: ''
      },
      rules: {
        reason: [
          { required: true, message: '请选择原因', trigger: 'change' }
        ]
      },
      dialogVisible: false,
      goodsId: null
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        this.$nextTick(() => {
          this.$refs['ruleForm'].resetFields()
        })
      }
    }
  },
  methods: {
    submit() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          const params = {
            goods_id: this.goodsId,
            check_reason: ''
          }
          if (this.form.reason === 3) {
            params.check_reason = this.form.other
          } else {
            params.check_reason = this.form.reason
          }
          itemDownShelf(params).then(res => {
            this.dialogVisible = false
            this.$emit('getList', true)
          })
        } else {
          this.$message({
            message: '请检查表单错误',
            type: 'error'
          })
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.tip {
  line-height: 35px;
  margin-bottom: 10px;
}
</style>
